package com.shiguiwu.springmybatis.app.service.Impl;

import com.shiguiwu.springmybatis.app.entity.WorkEnergizeDetail;
import com.shiguiwu.springmybatis.app.mapper.WorkEnergizeDetailMapper;
import com.shiguiwu.springmybatis.app.service.WorkEnergizeDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (WorkEnergizeDetail)表服务实现类
 *
 * @author makejava
 * @since 2022-11-24 21:41:50
 */
@Slf4j
@Service("workEnergizeDetailService")
public class WorkEnergizeDetailServiceImpl implements WorkEnergizeDetailService {
    @Resource
    private WorkEnergizeDetailMapper workEnergizeDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param macAddress 主键
     * @return 实例对象
     */
    @Override
    public WorkEnergizeDetail queryById(String macAddress) {
        return this.workEnergizeDetailDao.queryById(macAddress);
    }

    /**
     * 分页查询
     *
     * @param workEnergizeDetail 筛选条件
     * @param pageRequest        分页对象
     * @return 查询结果
     */
    @Override
    public Page<WorkEnergizeDetail> queryByPage(WorkEnergizeDetail workEnergizeDetail, PageRequest pageRequest) {
        long total = this.workEnergizeDetailDao.count(workEnergizeDetail);
        return new PageImpl<>(this.workEnergizeDetailDao.queryAllByLimit(workEnergizeDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param workEnergizeDetail 实例对象
     * @return 实例对象
     */
    @Override
    public WorkEnergizeDetail insert(WorkEnergizeDetail workEnergizeDetail) {
        this.workEnergizeDetailDao.insert(workEnergizeDetail);
        return workEnergizeDetail;
    }

    /**
     * 修改数据
     *
     * @param workEnergizeDetail 实例对象
     * @return 实例对象
     */
    @Override
    public WorkEnergizeDetail update(WorkEnergizeDetail workEnergizeDetail) {
        this.workEnergizeDetailDao.update(workEnergizeDetail);
        return this.queryById(workEnergizeDetail.getMacAddress());
    }

    /**
     * 通过主键删除数据
     *
     * @param macAddress 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String macAddress) {
        return this.workEnergizeDetailDao.deleteById(macAddress) > 0;
    }

    @Override
    public void testOne() {
        Integer integer = workEnergizeDetailDao.testOne();

        log.info("查询到的参数有 ===> {}", integer);
    }
}
